<!DOCTYPE html>
<html lang="en" class="no-js"><!--<![endif]-->
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>LayIM 登陆</title>
        <link rel="shortcut icon" href="https://tympanus.net/Tutorials/favicon.ico"> 
        <link rel="stylesheet" type="text/css" href="static/css/login/style3.css">
		<link rel="stylesheet" type="text/css" href="static/css/login/animate-custom.css">
		<link rel="stylesheet" href="/static/layui/css/layui.css">
		<script src="/static/layui/layui.js"></script>
	</head>
    <body>
        <div class="container">
            <header>
                <h1>LayIM 即时通讯系统</span></h1>
            </header>
            <section>				
                <div id="container_demo">
                    <a class="hiddenanchor" id="toregister"></a>
                    <a class="hiddenanchor" id="tologin"></a>
                    <div id="wrapper">
                        <div id="login" class="animate form">
                            <form action="" autocomplete="on" method="post" class="layui-form" lay-filter="login"> 
                                <h1>登陆</h1> 
                                <p> 
                                    <label for="email" class="uname" data-icon="u"> 电子邮件 </label>
                                    <input id="email"  name="email" required="required" type="email" placeholder="mymail@mail.com">
                                </p>
                                <p> 
                                    <label for="password" class="youpasswd" data-icon="p"> 密码 </label>
                                    <input id="password" name="password" required="required" type="password" placeholder="eg. X8df!90EO"> 
                                </p>
                                <p class="keeplogin"> 
									<input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping"> 
									<label for="loginkeeping">记住我</label>
								</p>
                                <p class="login button"> 
                                    <input type="submit" value="登陆"> 
								</p>
                                <p class="change_link">
									还没有账号 ?
									<a href="/#toregister" class="to_register">加入我们</a>
								</p>
                            </form>
                        </div>

                        <div id="register" class="animate form">
                            <form action="#" autocomplete="on" class="layui-form" lay-filter="register"> 
                                <h1> 注册 </h1> 
                                <p> 
                                    <label for="usernamesignup" class="uname" data-icon="u">用户名</label>
                                    <input id="usernamesignup" name="usernamesignup" required="required" type="text" placeholder="mysuperusername690">
                                </p>
                                <p> 
                                    <label for="emailsignup" class="youmail" data-icon="e"> 电子邮件</label>
                                    <input id="emailsignup" name="emailsignup" required="required" type="email" placeholder="mysupermail@mail.com"> 
                                </p>
                                <p> 
                                    <label for="passwordsignup" class="youpasswd" data-icon="p">密码 </label>
                                    <input id="passwordsignup" name="passwordsignup" required="required" type="password" placeholder="eg. X8df!90EO">
                                </p>
                                <p> 
                                    <label for="passwordsignup_confirm" class="youpasswd" data-icon="p">确认密码 </label>
                                    <input id="passwordsignup_confirm" name="passwordsignup_confirm" required="required" type="password" placeholder="eg. X8df!90EO">
                                </p>
                                <p class="signin button"> 
									<input type="submit" value="注册"> 
								</p>
                                <p class="change_link">  
									已经有账号 ?
									<a href="/#tologin" class="to_register"> 返回登陆 </a>
								</p>
                            </form>
                        </div>
						
                    </div>
                </div>  
            </section>
        </div>
<script type="text/javascript">
	layui.use(['layer', 'form', 'jquery'], function(){
	    //layui组件
		var layer = layui.layer, form = layui.form(), $ = layui.jquery;
		//判断用户是否是从激活链接过来的
		if (location.href.split("?").length == 2){
			var status = location.href.split("?")[1].split("=")[1];
			if (status == 1){
				layer.msg("激活成功，请登录！");
			}else{
				layer.msg("激活失败，请重新激活!");
			}
		}
		//监测邮件
		$("#emailsignup").blur(function() {
			$.ajax({
	    		url:"user/existEmail",
	    		type:"POST",
	    		dataType:"JSON",
	    		data:{email:$("#emailsignup").val()},
	    		success:function(data) {
	    			if(data.data){
	    				$("#emailsignup").val("").focus();
	    				layer.msg("此邮件已经被人注册过！");
	    			}
	    		},
	    		error:function(data) {
	    			layer.msg("服务器错误,请稍后再试！");
	    		}
	    	});
		});
		
	    //注册
	    form.on('submit(register)', function (data){
	    	var passwordsignup_confirm = $("#passwordsignup_confirm").val().trim();
	    	var passwordsignup = $("#passwordsignup").val().trim();
	    	if (passwordsignup != passwordsignup_confirm) {
	    		layer.msg("两次密码不一致!");
	    		$("#passwordsignup_confirm").val("");
	    		$("#passwordsignup").val("");
	    		return false;
	    	}
	    	var d = {
				'username':$("#usernamesignup").val(),
				'email':$("#emailsignup").val(),
				'password':passwordsignup
			};
	    	
	    	//loading层
	    	var index = layer.load(0, {
	    	    shade: [0.6,'#fff'] //0.1透明度的白色背景
	    	});
	    	$.ajax({
	    		url:"user/register",
	    		dataType:"JSON",
	    		contentType:"application/json",
	    		type:"POST",
	    		data:JSON.stringify(d),
	    		success:function(data) {
	    				layer.close(index);
	    				layer.msg(data.msg + ",请先激活再登陆！");
	    				window.location.href = "/#tologin";
	    		},
	    		error:function(data) {
	    			layer.msg("服务器错误,请稍后再试！");
	    		}
	    	});
	    	return false;
	    });
	    //登陆
	    form.on('submit(login)', function (data){
		    var d = {'email': $("#email").val(),'password': $("#password").val()};
	    	//loading层
	    	var index = layer.load(1, {
	    	    shade: [0.6,'#fff'] //0.1透明度的白色背景
	    	});
	    	$.ajax({
	    		url:"user/login",
	    		dataType:"JSON",
	    		contentType:"application/json",
	    		type:"POST",
	    		data:JSON.stringify(d),
	    		success:function(data) {
	    			layer.close(index);
	    			if (data.code == 1) {
	    				layer.msg(data.msg);
	    				$("#password").val("");
	    			} else if(data.code == 0) {
	    				var host = window.location.host;
	    				if(window.location.port != "") {
	    					host = host + ":" + window.location.host;
	    				}
	    				window.location.href = "http://" + host + "/user/index";
	    			}
	    		},
	    		error:function(data) {
	    			layer.msg("服务器错误,请稍后再试！");
	    		}
	    	});
	    	return false;
	    });
	});
</script> 
</body>
</html>